﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Xml;
using System.Text.RegularExpressions;

namespace Magento.Generation
{
    class Abstract
    {
        private List<String> messages = new List<string>();

        public List<String> Messages()
        {

            List<String> _temp = new List<string>();
            this.messages.ForEach(i => _temp.Add(i));
            this.cleanMessage();
            return _temp;
        }

        protected string getModuleName(string dir)
        {
            XmlDocument doc = new XmlDocument();
            XmlNode node;
            XmlElement element;
            var module_path = Path.Combine(dir, @"etc/module.xml");
            if (!File.Exists(module_path))
            {
                this.addMessage(module_path + " file not exist.");
                return null;
            }

            doc.Load(module_path);
            node = doc.SelectSingleNode(@"//config/module");
            element = (XmlElement)node;
            return element.GetAttribute("name").ToString();
        }

        protected void addMessage(string message)
        {
            this.messages.Add(message);
        }

        protected void cleanMessage()
        {
            this.messages.Clear();
        }
    }
}
